package cn.lanca.esaypoi.c202204.week_4.fri;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;

/**
 * @author meihongliang
 * @since 2022/4/29 14:26
 */
public class TestLocalDateTime {
    public static void main(String[] args) {
//        LocalDateTime parse = LocalDateTime.parse("2022-04-29 14:19:32", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//        System.out.println(parse);
//        System.out.println(parse.getDayOfWeek());
//        System.out.println(parse.getDayOfYear());
//        System.out.println(parse.getDayOfMonth());

//        System.out.println(ZonedDateTime.now());
//        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        System.out.println(Year.now().length());
        // 自定义日期格式
        DateTimeFormatter mm = new DateTimeFormatterBuilder()
                .appendValue(ChronoField.YEAR,4)
                .appendLiteral('-')
                .appendValue(ChronoField.MONTH_OF_YEAR,2)
                .appendLiteral('-')
                .appendValue(ChronoField.DAY_OF_MONTH,2)
                .appendLiteral(' ')
                .appendValue(ChronoField.HOUR_OF_DAY,2)
                .appendLiteral(':')
                .appendValue(ChronoField.MINUTE_OF_HOUR,2)
                .appendLiteral(':')
                .appendValue(ChronoField.SECOND_OF_MINUTE,2)
                .toFormatter();
        LocalDateTime now = LocalDateTime.now();
//        DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;//
//        DateTimeFormatter formatter = DateTimeFormatter.BASIC_ISO_DATE;//20220429
//        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;//2022-04-29
        DateTimeFormatter formatter = DateTimeFormatter.ISO_TIME;//
        String format = mm.format(now);
        System.out.println(format);

        System.out.println(LocalDateTime.parse(format, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
    }
}
